package requests

import (
	"card/app/requests/validators"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type MemberUpdateRequest struct {
	Email           string `json:"email" valid:"email"`
	Avatar          string `json:"avatar" valid:"avatar"`
	Tel             string `json:"tel" valid:"tel"`
	Password        string `json:"password" valid:"password"`
	ConfirmPassword string `json:"confirm_password" valid:"confirm_password"`
	VerifyCode      string `json:"verify_code" valid:"verify_code"`
}

func MemberUpdate(data interface{}, c *gin.Context) map[string][]string {
	rules := govalidator.MapData{
		"email":            []string{"email"},
		"Tel":              []string{"tel"},
		"password":         []string{"min:6", "max:16"},
		"confirm_password": []string{"required"},
	}
	messages := govalidator.MapData{
		"email":    []string{"email:邮箱格式错误"},
		"Tel":      []string{"tel:电话号码格式错误"},
		"password": []string{"min:密码最短6位", "max:密码最长16位"},
	}

	errs := validate(data, rules, messages)
	_data := data.(*MemberUpdateRequest)
	errs = validators.ValidatePasswordConfirm(_data.Password, _data.ConfirmPassword, errs)
	return errs
}
